package com.yanqu.road.dataHelper.action.zhounianqing;

import com.yanqu.road.dataHelper.action.excel.ZhouNianQingRankData;

import java.util.Comparator;

public class MammonRankDataSort implements Comparator<ZhouNianQingRankData> {

    @Override
    public int compare(ZhouNianQingRankData o1, ZhouNianQingRankData o2) {

        //5级称号-等级比较
        int ret  = getCompareLevelCount(o1, o2);
        if(ret != 0){
            return  ret;
        }
        //赚钱比较
        return o2.getEarnSpeed().compareTo(o1.getEarnSpeed());
    }

    private int getCompareLevelCount(ZhouNianQingRankData o1, ZhouNianQingRankData o2) {
        for(int level = 5; level >= 1; level--) {
            int o1L5 = 0, o2L5 = 0;
            if (o1.getMammonCountMap().containsKey(level)) {
                o1L5 = o1.getMammonCountMap().get(level);
            }
            if (o2.getMammonCountMap().containsKey(level)) {
                o2L5 = o2.getMammonCountMap().get(level);
            }
            if (o1L5 > o2L5) {
                return -1;
            } else if (o1L5 < o2L5) {
                return 1;
            }
        }
        return 0;
    }

}
